package com.example.test_1;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class demoAlertDialog extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_demo_alert_dialog);
    }

    /**
     普通对话框 new AlertDialog.Builder
     设置标题 setTitle
     设置文本内容 setMessage
     设置取消按钮 setNegativeButton
     设置确定按钮 setPositiveButton
     写入自己的代码，要去listener里面去写
     */
    public void put(View view) {
        AlertDialog alertDialog = new AlertDialog.Builder(this)
                .setTitle("温馨提示")
                .setMessage("确定要取消登录吗？")
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(demoAlertDialog.this, "点击到了取消按钮", Toast.LENGTH_SHORT).show();
                    }
                })
                .setPositiveButton("确定", null)
                .create();
        alertDialog.show();
    }
}